CGM - Assignment : Predicting Height of the Children 👧👦📏¶Malnutrition is a global health crisis and is a leading cause of death among children under 5 years.
Detecting malnutrition requires anthropometric measurements of weight, height, and middle-upper arm circumference.
evaluating the nutritional status in the samples.prone to errors that could arise, for example, from the inadequate training of personnel.Examples of various measurements are shown below:¶
NOTEBOOK Description 📗¶Exploratory Data AnalysisAdded 34 new featuresNOTEBOOK Contents ✍️¶Adding some new Features¶1. How we can leverage the provided BBox co-ordinates❓
Extensive Data Analysis - I¶1. Let's visualize the Feature-1: NOSE Top dist
2. Let's visualize the Feature-2: NOSE Bottom dist
3. Let's visualize the Feature-3: LEFT EYE Top dist
4. Let's visualize the Feature-4: RIGHT SHOULDER Top dist
5. Let's visualize the Feature-5: RIGHT ELBOW Top dist
6. Let's visualize the Feature-6: LEFT WRIST Top dist
7. Let's visualize the Feature-7: RIGHT HIP Top dist
8. Let's visualize the Feature-8: LEFT KNEE Bottom dist
9. Let's visualize the Feature-9: RIGHT ANKLE Bottom dist
Extensive Data Analysis - II¶1. Lets plot some depth images here..
Extensive Data Analysis - III¶import os
import sys
import math
import scipy as scipy
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import cv2
import ast
import plotly.express as px
import plotly.graph_objects as go
import hashlib
from IPython.display import display
from PIL import Image
from tqdm import tqdm
tqdm.pandas()
%matplotlib inline
# Setting the display option
pd.set_option('display.max_columns', 50)
# Defining the variables for better plotting
label_font_dict = {'family':'sans-serif','size':13.5,'color':'brown','style':'italic'}
title_font_dict = {'family':'sans-serif','size':17.5,'color':'Blue','style':'italic'}
# Storing the location of the 'height_and_pose' file
height_pose_xlsx_loc = os.path.join(os.getcwd(), "height_and_pose.xlsx")
height_pose_xlsx_loc
'E:\\STUDY\\PROJECTS\\Assignment_CGM\\height_and_pose.xlsx'
# Creating the dataframe from XLSX file
hp_data = pd.read_excel(height_pose_xlsx_loc)
hp_data
| Depthmap Image | Height(cm) | Pose | |
|---|---|---|---|
| 0 | 1d5fee00-ada4-11eb-a80b-3f50af21830f | 76.7 | [{'bbox_coordinates': [(158.91087, 92.53168), ... |
| 1 | 1eddf4c0-ad9f-11eb-a80b-ef4adba049aa | 66.4 | [{'bbox_coordinates': [(131.00702, 68.115364),... |
| 2 | 38e29bc0-8fc0-11eb-b5f2-0742da91b282 | 63.2 | [{'bbox_coordinates': [(116.070114, 37.567608)... |
| 3 | 6cd5d480-8b8b-11eb-b152-f7b115384fa9 | 87.1 | [{'bbox_coordinates': [(145.24242, 26.49348), ... |
| 4 | 76ed6fc0-8e1d-11eb-ad70-7be1a1219834 | 59.1 | [{'bbox_coordinates': [(150.17046, 65.00379), ... |
| 5 | 8d23fa60-9201-11eb-b3e6-cbfb48c6a300 | 86.4 | [{'bbox_coordinates': [(146.97789, 37.342777),... |
| 6 | 9dc3eba0-8d8d-11eb-8d3f-4776be867c61 | 100.6 | [{'bbox_coordinates': [(135.09724, 42.205784),... |
| 7 | 9dd020a0-8d8d-11eb-8d3f-bfd9f6bd04d4 | 106.1 | [{'bbox_coordinates': [(167.52087, 52.946323),... |
| 8 | d3757800-8dff-11eb-a328-472d4f8db277 | 99.9 | [{'bbox_coordinates': [(92.025406, 19.148962),... |
# Storing every row in the dataframe as a list
list_of_a_row = hp_data['Pose'].map(ast.literal_eval)
# Example of the first row the way it gets stored
list_of_a_row[0]
[{'bbox_coordinates': [(158.91087, 92.53168), (396.85934, 616.8171)],
'bbox_confidence_score': [0.99280316],
'key_points_coordinate': [{'nose': {'x': 265.9385, 'y': 182.3019}},
{'left_eye': {'x': 289.8317, 'y': 168.64862}},
{'right_eye': {'x': 245.45859, 'y': 165.2353}},
{'left_ear': {'x': 317.13824, 'y': 178.88858}},
{'right_ear': {'x': 221.56538, 'y': 172.06195}},
{'left_shoulder': {'x': 334.20483, 'y': 233.50165}},
{'right_shoulder': {'x': 221.56538, 'y': 243.7416}},
{'left_elbow': {'x': 378.57794, 'y': 284.7014}},
{'right_elbow': {'x': 194.25885, 'y': 308.5946}},
{'left_wrist': {'x': 358.09805, 'y': 342.72778}},
{'right_wrist': {'x': 235.21864, 'y': 315.42123}},
{'left_hip': {'x': 341.03146, 'y': 393.92752}},
{'right_hip': {'x': 269.3518, 'y': 404.16748}},
{'left_knee': {'x': 354.68472, 'y': 506.56696}},
{'right_knee': {'x': 231.80533, 'y': 486.08707}},
{'left_ankle': {'x': 313.7249, 'y': 489.50037}},
{'right_ankle': {'x': 214.73874, 'y': 547.52673}}],
'key_points_prob': [{'nose': {'score': 0.9733702}},
{'left_eye': {'score': 0.9789531}},
{'right_eye': {'score': 0.9747643}},
{'left_ear': {'score': 0.9491323}},
{'right_ear': {'score': 0.93967146}},
{'left_shoulder': {'score': 0.93360823}},
{'right_shoulder': {'score': 0.93219453}},
{'left_elbow': {'score': 0.9705547}},
{'right_elbow': {'score': 0.9635779}},
{'left_wrist': {'score': 0.95338464}},
{'right_wrist': {'score': 0.93387914}},
{'left_hip': {'score': 0.9077342}},
{'right_hip': {'score': 0.8869987}},
{'left_knee': {'score': 0.7880519}},
{'right_knee': {'score': 0.9456413}},
{'left_ankle': {'score': 0.8660142}},
{'right_ankle': {'score': 0.9553187}}],
'body_pose_score': 0.93252057}]
# Storing the list of every list of row created above
dict_of_a_row = list_of_a_row[list_of_a_row.str.len() > 0].explode()
# Example of the first row dict the way it gets stored
dict_of_a_row.iloc[0]
{'bbox_coordinates': [(158.91087, 92.53168), (396.85934, 616.8171)],
'bbox_confidence_score': [0.99280316],
'key_points_coordinate': [{'nose': {'x': 265.9385, 'y': 182.3019}},
{'left_eye': {'x': 289.8317, 'y': 168.64862}},
{'right_eye': {'x': 245.45859, 'y': 165.2353}},
{'left_ear': {'x': 317.13824, 'y': 178.88858}},
{'right_ear': {'x': 221.56538, 'y': 172.06195}},
{'left_shoulder': {'x': 334.20483, 'y': 233.50165}},
{'right_shoulder': {'x': 221.56538, 'y': 243.7416}},
{'left_elbow': {'x': 378.57794, 'y': 284.7014}},
{'right_elbow': {'x': 194.25885, 'y': 308.5946}},
{'left_wrist': {'x': 358.09805, 'y': 342.72778}},
{'right_wrist': {'x': 235.21864, 'y': 315.42123}},
{'left_hip': {'x': 341.03146, 'y': 393.92752}},
{'right_hip': {'x': 269.3518, 'y': 404.16748}},
{'left_knee': {'x': 354.68472, 'y': 506.56696}},
{'right_knee': {'x': 231.80533, 'y': 486.08707}},
{'left_ankle': {'x': 313.7249, 'y': 489.50037}},
{'right_ankle': {'x': 214.73874, 'y': 547.52673}}],
'key_points_prob': [{'nose': {'score': 0.9733702}},
{'left_eye': {'score': 0.9789531}},
{'right_eye': {'score': 0.9747643}},
{'left_ear': {'score': 0.9491323}},
{'right_ear': {'score': 0.93967146}},
{'left_shoulder': {'score': 0.93360823}},
{'right_shoulder': {'score': 0.93219453}},
{'left_elbow': {'score': 0.9705547}},
{'right_elbow': {'score': 0.9635779}},
{'left_wrist': {'score': 0.95338464}},
{'right_wrist': {'score': 0.93387914}},
{'left_hip': {'score': 0.9077342}},
{'right_hip': {'score': 0.8869987}},
{'left_knee': {'score': 0.7880519}},
{'right_knee': {'score': 0.9456413}},
{'left_ankle': {'score': 0.8660142}},
{'right_ankle': {'score': 0.9553187}}],
'body_pose_score': 0.93252057}
# Updated dataframe with the child entities
child_entities_df = pd.DataFrame(list(dict_of_a_row), index=dict_of_a_row.index)
child_entities_df
| bbox_coordinates | bbox_confidence_score | key_points_coordinate | key_points_prob | body_pose_score | |
|---|---|---|---|---|---|
| 0 | [(158.91087, 92.53168), (396.85934, 616.8171)] | [0.99280316] | [{'nose': {'x': 265.9385, 'y': 182.3019}}, {'l... | [{'nose': {'score': 0.9733702}}, {'left_eye': ... | 0.932521 |
| 1 | [(131.00702, 68.115364), (420.1891, 559.3997)] | [0.9962908] | [{'nose': {'x': 305.9835, 'y': 200.21199}}, {'... | [{'nose': {'score': 0.4369605}}, {'left_eye': ... | 0.778794 |
| 2 | [(116.070114, 37.567608), (395.045, 542.00757)] | [0.98634934] | [{'nose': {'x': 191.51735, 'y': 123.93983}}, {... | [{'nose': {'score': 0.64242655}}, {'left_eye':... | 0.877052 |
| 3 | [(145.24242, 26.49348), (346.4439, 637.2346)] | [0.999383] | [{'nose': {'x': 239.8789, 'y': 142.99553}}, {'... | [{'nose': {'score': 0.96169055}}, {'left_eye':... | 0.955477 |
| 4 | [(150.17046, 65.00379), (373.36887, 611.4233)] | [0.9969072] | [{'nose': {'x': 167.49805, 'y': 155.00647}}, {... | [{'nose': {'score': 0.58681124}}, {'left_eye':... | 0.853830 |
| 5 | [(146.97789, 37.342777), (323.04355, 616.20996)] | [0.9988991] | [{'nose': {'x': 304.73105, 'y': 143.99603}}, {... | [{'nose': {'score': 0.9652283}}, {'left_eye': ... | 0.908704 |
| 6 | [(135.09724, 42.205784), (308.40625, 609.4822)] | [0.99963164] | [{'nose': {'x': 212.51872, 'y': 161.49629}}, {... | [{'nose': {'score': 0.96656704}}, {'left_eye':... | 0.960757 |
| 7 | [(167.52087, 52.946323), (322.8788, 583.97754)] | [0.999605] | [{'nose': {'x': 222.72783, 'y': 157.70052}}, {... | [{'nose': {'score': 0.9798624}}, {'left_eye': ... | 0.961107 |
| 8 | [(92.025406, 19.148962), (295.21625, 625.0551)] | [0.99962795] | [{'nose': {'x': 235.04018, 'y': 126.83931}}, {... | [{'nose': {'score': 0.7892967}}, {'left_eye': ... | 0.915556 |
# I'm dropping the 'score' and 'probabilities' columns
child_entities_df.drop(['bbox_confidence_score', 'key_points_prob', 'body_pose_score'], axis=1, inplace=True)
REASONING
# Creating a list of all the sub-entities within a keypoint co-orrdinates
## For example, X & Y co-orrdinates of nose, left_eye and others
each_body_component = [{k:v for entity in category for k, v in entity.items()} for category in child_entities_df['key_points_coordinate']]
# Dictionary containing the X & Y co-orrdinates of every body part
each_body_component[0]
{'nose': {'x': 265.9385, 'y': 182.3019},
'left_eye': {'x': 289.8317, 'y': 168.64862},
'right_eye': {'x': 245.45859, 'y': 165.2353},
'left_ear': {'x': 317.13824, 'y': 178.88858},
'right_ear': {'x': 221.56538, 'y': 172.06195},
'left_shoulder': {'x': 334.20483, 'y': 233.50165},
'right_shoulder': {'x': 221.56538, 'y': 243.7416},
'left_elbow': {'x': 378.57794, 'y': 284.7014},
'right_elbow': {'x': 194.25885, 'y': 308.5946},
'left_wrist': {'x': 358.09805, 'y': 342.72778},
'right_wrist': {'x': 235.21864, 'y': 315.42123},
'left_hip': {'x': 341.03146, 'y': 393.92752},
'right_hip': {'x': 269.3518, 'y': 404.16748},
'left_knee': {'x': 354.68472, 'y': 506.56696},
'right_knee': {'x': 231.80533, 'y': 486.08707},
'left_ankle': {'x': 313.7249, 'y': 489.50037},
'right_ankle': {'x': 214.73874, 'y': 547.52673}}
# Joining the X & Y co-orrdinates of every body part with the overall bounding box
child_entities_df = child_entities_df.join(pd.DataFrame(each_body_component, index=child_entities_df.index))
child_entities_df.drop(labels=['key_points_coordinate'], axis=1, inplace=True)
child_entities_df.head()
| bbox_coordinates | nose | left_eye | right_eye | left_ear | right_ear | left_shoulder | right_shoulder | left_elbow | right_elbow | left_wrist | right_wrist | left_hip | right_hip | left_knee | right_knee | left_ankle | right_ankle | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | [(158.91087, 92.53168), (396.85934, 616.8171)] | {'x': 265.9385, 'y': 182.3019} | {'x': 289.8317, 'y': 168.64862} | {'x': 245.45859, 'y': 165.2353} | {'x': 317.13824, 'y': 178.88858} | {'x': 221.56538, 'y': 172.06195} | {'x': 334.20483, 'y': 233.50165} | {'x': 221.56538, 'y': 243.7416} | {'x': 378.57794, 'y': 284.7014} | {'x': 194.25885, 'y': 308.5946} | {'x': 358.09805, 'y': 342.72778} | {'x': 235.21864, 'y': 315.42123} | {'x': 341.03146, 'y': 393.92752} | {'x': 269.3518, 'y': 404.16748} | {'x': 354.68472, 'y': 506.56696} | {'x': 231.80533, 'y': 486.08707} | {'x': 313.7249, 'y': 489.50037} | {'x': 214.73874, 'y': 547.52673} |
| 1 | [(131.00702, 68.115364), (420.1891, 559.3997)] | {'x': 305.9835, 'y': 200.21199} | {'x': 197.23564, 'y': 152.235} | {'x': 305.9835, 'y': 181.0212} | {'x': 216.42644, 'y': 177.82274} | {'x': 286.7927, 'y': 197.01353} | {'x': 210.0295, 'y': 219.40279} | {'x': 305.9835, 'y': 228.99818} | {'x': 184.44177, 'y': 187.41814} | {'x': 373.15128, 'y': 222.60126} | {'x': 203.63257, 'y': 129.84575} | {'x': 398.73898, 'y': 184.21967} | {'x': 242.01416, 'y': 353.73837} | {'x': 305.9835, 'y': 350.5399} | {'x': 235.61723, 'y': 427.30307} | {'x': 344.36508, 'y': 398.51688} | {'x': 267.6019, 'y': 494.47086} | {'x': 360.3574, 'y': 472.0816} |
| 2 | [(116.070114, 37.567608), (395.045, 542.00757)] | {'x': 191.51735, 'y': 123.93983} | {'x': 201.36969, 'y': 123.93983} | {'x': 299.89313, 'y': 137.0763} | {'x': 198.08557, 'y': 150.21274} | {'x': 299.89313, 'y': 140.3604} | {'x': 201.36969, 'y': 196.19034} | {'x': 296.609, 'y': 202.75858} | {'x': 191.51735, 'y': 127.223946} | {'x': 342.5866, 'y': 153.49686} | {'x': 204.65381, 'y': 97.666916} | {'x': 362.2913, 'y': 100.951035} | {'x': 234.21083, 'y': 350.5437} | {'x': 293.3249, 'y': 357.11194} | {'x': 224.35849, 'y': 432.64658} | {'x': 319.5978, 'y': 416.22598} | {'x': 250.6314, 'y': 508.18118} | {'x': 306.46133, 'y': 488.4765} |
| 3 | [(145.24242, 26.49348), (346.4439, 637.2346)] | {'x': 239.8789, 'y': 142.99553} | {'x': 263.73596, 'y': 127.090805} | {'x': 223.97418, 'y': 127.090805} | {'x': 295.5454, 'y': 135.04317} | {'x': 208.06947, 'y': 135.04317} | {'x': 311.45013, 'y': 202.63821} | {'x': 204.09329, 'y': 194.68585} | {'x': 323.37866, 'y': 278.1856} | {'x': 172.28386, 'y': 270.23328} | {'x': 323.37866, 'y': 341.8045} | {'x': 160.35532, 'y': 337.8283} | {'x': 271.68832, 'y': 373.61392} | {'x': 208.06947, 'y': 369.63776} | {'x': 259.7598, 'y': 476.9946} | {'x': 196.14093, 'y': 469.04224} | {'x': 243.85509, 'y': 560.4944} | {'x': 188.18857, 'y': 556.5182} |
| 4 | [(150.17046, 65.00379), (373.36887, 611.4233)] | {'x': 167.49805, 'y': 155.00647} | {'x': 171.05548, 'y': 151.44904} | {'x': 174.61288, 'y': 151.44904} | {'x': 213.7445, 'y': 169.23615} | {'x': 295.56512, 'y': 147.89163} | {'x': 195.9574, 'y': 219.04001} | {'x': 309.7948, 'y': 176.35098} | {'x': 160.38321, 'y': 194.13806} | {'x': 348.92642, 'y': 140.7768} | {'x': 167.49805, 'y': 147.89163} | {'x': 331.1393, 'y': 98.08776} | {'x': 235.08902, 'y': 361.33676} | {'x': 309.7948, 'y': 350.6645} | {'x': 203.07224, 'y': 443.15738} | {'x': 324.02448, 'y': 450.27222} | {'x': 224.41675, 'y': 539.2077} | {'x': 309.7948, 'y': 546.3225} |
# Getting the body parts names in a list
body_parts_cols = list(child_entities_df.columns)[1:]
body_parts_cols
['nose', 'left_eye', 'right_eye', 'left_ear', 'right_ear', 'left_shoulder', 'right_shoulder', 'left_elbow', 'right_elbow', 'left_wrist', 'right_wrist', 'left_hip', 'right_hip', 'left_knee', 'right_knee', 'left_ankle', 'right_ankle']
# Storing only the co-orrdinates values in the dataframe
for body_part_col in body_parts_cols:
child_entities_df[body_part_col] = child_entities_df[body_part_col].apply(lambda val_dict : tuple([v for v in val_dict.values()]))
# Dataframe with the co-orrdinates values of the overall bounding box & body parts
child_entities_df
| bbox_coordinates | nose | left_eye | right_eye | left_ear | right_ear | left_shoulder | right_shoulder | left_elbow | right_elbow | left_wrist | right_wrist | left_hip | right_hip | left_knee | right_knee | left_ankle | right_ankle | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | [(158.91087, 92.53168), (396.85934, 616.8171)] | (265.9385, 182.3019) | (289.8317, 168.64862) | (245.45859, 165.2353) | (317.13824, 178.88858) | (221.56538, 172.06195) | (334.20483, 233.50165) | (221.56538, 243.7416) | (378.57794, 284.7014) | (194.25885, 308.5946) | (358.09805, 342.72778) | (235.21864, 315.42123) | (341.03146, 393.92752) | (269.3518, 404.16748) | (354.68472, 506.56696) | (231.80533, 486.08707) | (313.7249, 489.50037) | (214.73874, 547.52673) |
| 1 | [(131.00702, 68.115364), (420.1891, 559.3997)] | (305.9835, 200.21199) | (197.23564, 152.235) | (305.9835, 181.0212) | (216.42644, 177.82274) | (286.7927, 197.01353) | (210.0295, 219.40279) | (305.9835, 228.99818) | (184.44177, 187.41814) | (373.15128, 222.60126) | (203.63257, 129.84575) | (398.73898, 184.21967) | (242.01416, 353.73837) | (305.9835, 350.5399) | (235.61723, 427.30307) | (344.36508, 398.51688) | (267.6019, 494.47086) | (360.3574, 472.0816) |
| 2 | [(116.070114, 37.567608), (395.045, 542.00757)] | (191.51735, 123.93983) | (201.36969, 123.93983) | (299.89313, 137.0763) | (198.08557, 150.21274) | (299.89313, 140.3604) | (201.36969, 196.19034) | (296.609, 202.75858) | (191.51735, 127.223946) | (342.5866, 153.49686) | (204.65381, 97.666916) | (362.2913, 100.951035) | (234.21083, 350.5437) | (293.3249, 357.11194) | (224.35849, 432.64658) | (319.5978, 416.22598) | (250.6314, 508.18118) | (306.46133, 488.4765) |
| 3 | [(145.24242, 26.49348), (346.4439, 637.2346)] | (239.8789, 142.99553) | (263.73596, 127.090805) | (223.97418, 127.090805) | (295.5454, 135.04317) | (208.06947, 135.04317) | (311.45013, 202.63821) | (204.09329, 194.68585) | (323.37866, 278.1856) | (172.28386, 270.23328) | (323.37866, 341.8045) | (160.35532, 337.8283) | (271.68832, 373.61392) | (208.06947, 369.63776) | (259.7598, 476.9946) | (196.14093, 469.04224) | (243.85509, 560.4944) | (188.18857, 556.5182) |
| 4 | [(150.17046, 65.00379), (373.36887, 611.4233)] | (167.49805, 155.00647) | (171.05548, 151.44904) | (174.61288, 151.44904) | (213.7445, 169.23615) | (295.56512, 147.89163) | (195.9574, 219.04001) | (309.7948, 176.35098) | (160.38321, 194.13806) | (348.92642, 140.7768) | (167.49805, 147.89163) | (331.1393, 98.08776) | (235.08902, 361.33676) | (309.7948, 350.6645) | (203.07224, 443.15738) | (324.02448, 450.27222) | (224.41675, 539.2077) | (309.7948, 546.3225) |
| 5 | [(146.97789, 37.342777), (323.04355, 616.20996)] | (304.73105, 143.99603) | (300.96237, 128.92137) | (293.42505, 128.92137) | (233.12637, 136.45871) | (236.89505, 140.22737) | (191.67105, 200.52603) | (263.2757, 211.83203) | (165.29037, 275.89935) | (289.65637, 313.58603) | (221.82037, 298.51135) | (304.73105, 279.66803) | (199.20837, 362.5787) | (255.73837, 373.8847) | (218.05171, 479.40735) | (259.50705, 490.71338) | (210.51437, 581.1614) | (263.2757, 592.46735) |
| 6 | [(135.09724, 42.205784), (308.40625, 609.4822)] | (212.51872, 161.49629) | (227.29155, 143.03027) | (194.05269, 143.03027) | (256.8372, 139.33707) | (171.89346, 139.33707) | (271.61002, 216.8944) | (160.81384, 220.5876) | (286.38284, 301.83813) | (149.73422, 305.53134) | (290.07605, 372.00903) | (149.73422, 379.39545) | (253.144, 349.8498) | (190.35948, 349.8498) | (245.75758, 449.56638) | (190.35948, 453.25958) | (238.37117, 519.7373) | (194.05269, 530.8169) |
| 7 | [(167.52087, 52.946323), (322.8788, 583.97754)] | (222.72783, 157.70052) | (240.01399, 136.9571) | (208.89888, 140.41435) | (267.67188, 143.87158) | (195.06995, 150.78606) | (291.8725, 209.55904) | (191.61272, 209.55904) | (302.2442, 299.4471) | (184.69824, 299.4471) | (305.70145, 368.5918) | (184.69824, 382.42075) | (271.1291, 361.67734) | (215.81335, 361.67734) | (260.7574, 451.56543) | (222.72783, 455.02267) | (253.84293, 524.16736) | (229.64229, 524.16736) |
| 8 | [(92.025406, 19.148962), (295.21625, 625.0551)] | (235.04018, 126.83931) | (235.04018, 118.949905) | (242.92958, 111.0605) | (148.25676, 115.0052) | (235.04018, 111.0605) | (120.643845, 189.95453) | (254.76369, 193.89923) | (108.80974, 296.46146) | (270.54248, 300.40616) | (112.75444, 367.4661) | (282.3766, 371.4108) | (160.09085, 367.4661) | (231.09547, 371.4108) | (164.03555, 477.91772) | (231.09547, 470.02832) | (140.36736, 588.3694) | (250.81898, 580.48) |
def calc_distances(bb_coords, bp_coords):
"""
Description : This function is created for calculating the 2 Euclidean Distances:
- 1 : From the top of the bounding box to the body part
- 2 : From the bottom of the bounding box to the body part
Input Parameters : It accepts 2 inputs:
- bb_coords : `list`
Containing the X & Y coordinates of the bounding box top & bottom
- bp_cords : `list`
Containing the X & Y coordinates of the specific body part
Returns : It returns 1 list object.
- distances : `list`
Containing the 2 distances in a single container.
"""
# Storing the top coordinate as an array
top_array = np.array(bb_coords)[0]
# Storing the bottom coordinate as an array
bottom_array = np.array(bb_coords)[1]
# Storing the body-part coordinate as an array
body_part_array = np.array(bp_coords)
# Euclidean distance fron the top to body part
diff_from_top = np.sqrt(np.sum(np.square(top_array - body_part_array)))
# Euclidean distance fron the bottom to body part
diff_from_bottom = np.sqrt(np.sum(np.square(bottom_array - body_part_array)))
# Both the distances
distances = [diff_from_top, diff_from_bottom]
return distances
# Storing the top & based distances based on the co-orrdinates values in the dataframe
for body_part_col in body_parts_cols:
col_name = body_part_col + "_dists"
child_entities_df[col_name] = child_entities_df[['bbox_coordinates',body_part_col]].apply(lambda row: calc_distances(row['bbox_coordinates'], row[body_part_col]), axis=1)
# Shape of the Dataframe after adding the features
child_entities_df.shape
(9, 35)
# Displaying some records
child_entities_df.head()
| bbox_coordinates | nose | left_eye | right_eye | left_ear | right_ear | left_shoulder | right_shoulder | left_elbow | right_elbow | left_wrist | right_wrist | left_hip | right_hip | left_knee | right_knee | left_ankle | right_ankle | nose_dists | left_eye_dists | right_eye_dists | left_ear_dists | right_ear_dists | left_shoulder_dists | right_shoulder_dists | left_elbow_dists | right_elbow_dists | left_wrist_dists | right_wrist_dists | left_hip_dists | right_hip_dists | left_knee_dists | right_knee_dists | left_ankle_dists | right_ankle_dists | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | [(158.91087, 92.53168), (396.85934, 616.8171)] | (265.9385, 182.3019) | (289.8317, 168.64862) | (245.45859, 165.2353) | (317.13824, 178.88858) | (221.56538, 172.06195) | (334.20483, 233.50165) | (221.56538, 243.7416) | (378.57794, 284.7014) | (194.25885, 308.5946) | (358.09805, 342.72778) | (235.21864, 315.42123) | (341.03146, 393.92752) | (269.3518, 404.16748) | (354.68472, 506.56696) | (231.80533, 486.08707) | (313.7249, 489.50037) | (214.73874, 547.52673) | [139.69110917401042, 453.81023057809705] | [151.4399296184877, 460.77098670541307] | [113.03240331118683, 476.28595317498343] | [180.25929877464546, 445.12564789573787] | [101.24550098455241, 478.05346548686794] | [224.94555975676096, 388.40226805728435] | [163.67659432474304, 412.2054113093757] | [291.86096506258474, 332.61847178479127] | [218.93529886477148, 368.8469439408304] | [319.80247205355124, 276.81653299708546] | [235.58995577395783, 342.0046583740445] | [352.1467899488134, 229.7749269565128] | [330.62678485099315, 247.94764294704632] | [457.9875690763898, 118.04148398831656] | [400.24923147551914, 210.55442754993538] | [426.0886348227995, 152.05553213219997] | [458.40729334647307, 194.85653265697016] |
| 1 | [(131.00702, 68.115364), (420.1891, 559.3997)] | (305.9835, 200.21199) | (197.23564, 152.235) | (305.9835, 181.0212) | (216.42644, 177.82274) | (286.7927, 197.01353) | (210.0295, 219.40279) | (305.9835, 228.99818) | (184.44177, 187.41814) | (373.15128, 222.60126) | (203.63257, 129.84575) | (398.73898, 184.21967) | (242.01416, 353.73837) | (305.9835, 350.5399) | (235.61723, 427.30307) | (344.36508, 398.51688) | (267.6019, 494.47086) | (360.3574, 472.0816) | [219.24024984882283, 376.90679230600784] | [107.06233356263488, 464.210446082444] | [208.2414376536267, 395.23816659529484] | [139.04023037215444, 432.57392202156296] | [202.19771336794577, 386.1584334702907] | [170.68227093361477, 399.7060873713436] | [237.69738963076614, 349.5827276763977] | [130.72270219387553, 440.39423768047027] | [287.2276705226542, 340.0672664294316] | [95.31584898909254, 481.05439052797703] | [291.82291252947095, 375.79271222153227] | [306.4361053914105, 272.1082356368005] | [332.23543924151994, 238.04481747645764] | [374.11108534469616, 226.9720133687275] | [393.30245809308366, 177.85545754941796] | [447.7020998516988, 165.827042027486] | [464.5323633872586, 105.85028536806131] |
| 2 | [(116.070114, 37.567608), (395.045, 542.00757)] | (191.51735, 123.93983) | (201.36969, 123.93983) | (299.89313, 137.0763) | (198.08557, 150.21274) | (299.89313, 140.3604) | (201.36969, 196.19034) | (296.609, 202.75858) | (191.51735, 127.223946) | (342.5866, 153.49686) | (204.65381, 97.666916) | (362.2913, 100.951035) | (234.21083, 350.5437) | (293.3249, 357.11194) | (224.35849, 432.64658) | (319.5978, 416.22598) | (250.6314, 508.18118) | (306.46133, 488.4765) | [114.68411465088343, 464.97756886029464] | [121.39266204757624, 460.75021533614466] | [209.02842150025225, 415.9605892248805] | [139.33937270630062, 438.51591291611504] | [210.611631441598, 412.76425176304423] | [180.10327252141641, 396.3580228385304] | [244.7086974106678, 353.241451859801] | [117.17740551663508, 462.0270111726108] | [254.45885698687655, 392.0362936199455] | [107.04670952018692, 483.41226921413966] | [254.24856194974026, 442.2710389906807] | [334.53140800317254, 250.0520820848445] | [365.41461283483454, 211.02931724551186] | [409.65078602792175, 202.71583763919438] | [429.8903135152093, 146.67408895496197] | [489.4730573183502, 148.32232645624225] | [489.4564781618753, 103.50189392476742] |
| 3 | [(145.24242, 26.49348), (346.4439, 637.2346)] | (239.8789, 142.99553) | (263.73596, 127.090805) | (223.97418, 127.090805) | (295.5454, 135.04317) | (208.06947, 135.04317) | (311.45013, 202.63821) | (204.09329, 194.68585) | (323.37866, 278.1856) | (172.28386, 270.23328) | (323.37866, 341.8045) | (160.35532, 337.8283) | (271.68832, 373.61392) | (208.06947, 369.63776) | (259.7598, 476.9946) | (196.14093, 469.04224) | (243.85509, 560.4944) | (188.18857, 556.5182) | [150.09593932213122, 505.59703078584715] | [155.43661350816677, 516.8048905690092] | [127.74393069673886, 524.6384697045008] | [185.40232198108117, 504.7641921409391] | [125.42038674313916, 520.9066281429617] | [242.1816854558102, 436.00296574661627] | [178.19118447884506, 464.8796535598591] | [308.3527902767089, 359.789090575656] | [245.2352535450676, 406.2286159474047] | [362.1512934324245, 296.3291232435104] | [311.70141143543515, 352.5238886743796] | [369.43357385679445, 274.0150719664865] | [348.84844145906817, 301.2566209327365] | [464.82845162846775, 182.18394768148482] | [445.4661191356282, 225.5651851531847] | [543.0298714116705, 128.11526932124872] | [531.7617658415288, 177.65102505296414] |
| 4 | [(150.17046, 65.00379), (373.36887, 611.4233)] | (167.49805, 155.00647) | (171.05548, 151.44904) | (174.61288, 151.44904) | (213.7445, 169.23615) | (295.56512, 147.89163) | (195.9574, 219.04001) | (309.7948, 176.35098) | (160.38321, 194.13806) | (348.92642, 140.7768) | (167.49805, 147.89163) | (331.1393, 98.08776) | (235.08902, 361.33676) | (309.7948, 350.6645) | (203.07224, 443.15738) | (324.02448, 450.27222) | (224.41675, 539.2077) | (309.7948, 546.3225) | [91.65548419156653, 500.69862915202924] | [88.93236367016735, 502.50077376640905] | [89.83436504489192, 501.07909896884325] | [122.09030851419453, 470.1163846570543] | [167.36188686908736, 470.01599186309767] | [160.69723378593673, 430.6268407319556] | [194.6230372831842, 439.6926039934574] | [129.53748473316674, 468.49745238100627] | [212.70985092369773, 471.2807669789343] | [84.67962798143188, 507.19266913123005] | [183.96812256993468, 515.0696197694798] | [308.2602649409984, 285.7701775994026] | [327.23381725937145, 268.396747658769] | [381.8360066272647, 239.40418129766098] | [422.6783451098782, 168.53646314563065] | [479.9811036260201, 165.53497194204735] | [507.0972594251518, 90.99327742753806] |
# Columns containing both the distances
body_parts_cols_dists = [bp + "_dists" for bp in body_parts_cols]
body_parts_cols_dists
['nose_dists', 'left_eye_dists', 'right_eye_dists', 'left_ear_dists', 'right_ear_dists', 'left_shoulder_dists', 'right_shoulder_dists', 'left_elbow_dists', 'right_elbow_dists', 'left_wrist_dists', 'right_wrist_dists', 'left_hip_dists', 'right_hip_dists', 'left_knee_dists', 'right_knee_dists', 'left_ankle_dists', 'right_ankle_dists']
# Number of columns having distances of body parts
len(body_parts_cols_dists)
17
# Shape of the DataFrame having distances for all the body parts
child_entities_df[body_parts_cols_dists].shape
(9, 17)
# DataFrame having distances for all the body parts
body_parts_distances_df = child_entities_df[body_parts_cols_dists].copy(deep=True)
body_parts_distances_df.head()
| nose_dists | left_eye_dists | right_eye_dists | left_ear_dists | right_ear_dists | left_shoulder_dists | right_shoulder_dists | left_elbow_dists | right_elbow_dists | left_wrist_dists | right_wrist_dists | left_hip_dists | right_hip_dists | left_knee_dists | right_knee_dists | left_ankle_dists | right_ankle_dists | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | [139.69110917401042, 453.81023057809705] | [151.4399296184877, 460.77098670541307] | [113.03240331118683, 476.28595317498343] | [180.25929877464546, 445.12564789573787] | [101.24550098455241, 478.05346548686794] | [224.94555975676096, 388.40226805728435] | [163.67659432474304, 412.2054113093757] | [291.86096506258474, 332.61847178479127] | [218.93529886477148, 368.8469439408304] | [319.80247205355124, 276.81653299708546] | [235.58995577395783, 342.0046583740445] | [352.1467899488134, 229.7749269565128] | [330.62678485099315, 247.94764294704632] | [457.9875690763898, 118.04148398831656] | [400.24923147551914, 210.55442754993538] | [426.0886348227995, 152.05553213219997] | [458.40729334647307, 194.85653265697016] |
| 1 | [219.24024984882283, 376.90679230600784] | [107.06233356263488, 464.210446082444] | [208.2414376536267, 395.23816659529484] | [139.04023037215444, 432.57392202156296] | [202.19771336794577, 386.1584334702907] | [170.68227093361477, 399.7060873713436] | [237.69738963076614, 349.5827276763977] | [130.72270219387553, 440.39423768047027] | [287.2276705226542, 340.0672664294316] | [95.31584898909254, 481.05439052797703] | [291.82291252947095, 375.79271222153227] | [306.4361053914105, 272.1082356368005] | [332.23543924151994, 238.04481747645764] | [374.11108534469616, 226.9720133687275] | [393.30245809308366, 177.85545754941796] | [447.7020998516988, 165.827042027486] | [464.5323633872586, 105.85028536806131] |
| 2 | [114.68411465088343, 464.97756886029464] | [121.39266204757624, 460.75021533614466] | [209.02842150025225, 415.9605892248805] | [139.33937270630062, 438.51591291611504] | [210.611631441598, 412.76425176304423] | [180.10327252141641, 396.3580228385304] | [244.7086974106678, 353.241451859801] | [117.17740551663508, 462.0270111726108] | [254.45885698687655, 392.0362936199455] | [107.04670952018692, 483.41226921413966] | [254.24856194974026, 442.2710389906807] | [334.53140800317254, 250.0520820848445] | [365.41461283483454, 211.02931724551186] | [409.65078602792175, 202.71583763919438] | [429.8903135152093, 146.67408895496197] | [489.4730573183502, 148.32232645624225] | [489.4564781618753, 103.50189392476742] |
| 3 | [150.09593932213122, 505.59703078584715] | [155.43661350816677, 516.8048905690092] | [127.74393069673886, 524.6384697045008] | [185.40232198108117, 504.7641921409391] | [125.42038674313916, 520.9066281429617] | [242.1816854558102, 436.00296574661627] | [178.19118447884506, 464.8796535598591] | [308.3527902767089, 359.789090575656] | [245.2352535450676, 406.2286159474047] | [362.1512934324245, 296.3291232435104] | [311.70141143543515, 352.5238886743796] | [369.43357385679445, 274.0150719664865] | [348.84844145906817, 301.2566209327365] | [464.82845162846775, 182.18394768148482] | [445.4661191356282, 225.5651851531847] | [543.0298714116705, 128.11526932124872] | [531.7617658415288, 177.65102505296414] |
| 4 | [91.65548419156653, 500.69862915202924] | [88.93236367016735, 502.50077376640905] | [89.83436504489192, 501.07909896884325] | [122.09030851419453, 470.1163846570543] | [167.36188686908736, 470.01599186309767] | [160.69723378593673, 430.6268407319556] | [194.6230372831842, 439.6926039934574] | [129.53748473316674, 468.49745238100627] | [212.70985092369773, 471.2807669789343] | [84.67962798143188, 507.19266913123005] | [183.96812256993468, 515.0696197694798] | [308.2602649409984, 285.7701775994026] | [327.23381725937145, 268.396747658769] | [381.8360066272647, 239.40418129766098] | [422.6783451098782, 168.53646314563065] | [479.9811036260201, 165.53497194204735] | [507.0972594251518, 90.99327742753806] |
# Storing the Top & Bottom Distances of each body part seperately
for col in body_parts_cols_dists:
bp_name = "_".join(col.split("_")[0:-1])
bp_name_top = bp_name + "_top_dist"
bp_name_bottom = bp_name + "_bottom_dist"
body_parts_distances_df = body_parts_distances_df.merge(body_parts_distances_df[col].apply(lambda row: pd.Series({bp_name_top:row[0],
bp_name_bottom:row[1]})),
left_index=True, right_index=True)
# Columns containing both the distances
body_parts_cols_top_dists = [bp + "_top_dist" for bp in body_parts_cols]
body_parts_cols_bottom_dists = [bp + "_bottom_dist" for bp in body_parts_cols]
both_dists_cols = []
for i in range(len(body_parts_cols_top_dists)):
both_dists_cols.append(body_parts_cols_top_dists[i])
both_dists_cols.append(body_parts_cols_bottom_dists[i])
len(both_dists_cols)
34
OBSERVATION
# This dataframe is having the TOP & BOTTOM distances of every body part
body_parts_both_dists_df = body_parts_distances_df[both_dists_cols].copy(deep=True)
body_parts_both_dists_df = body_parts_both_dists_df.applymap(lambda val: np.round(val,3))
body_parts_both_dists_df
| nose_top_dist | nose_bottom_dist | left_eye_top_dist | left_eye_bottom_dist | right_eye_top_dist | right_eye_bottom_dist | left_ear_top_dist | left_ear_bottom_dist | right_ear_top_dist | right_ear_bottom_dist | left_shoulder_top_dist | left_shoulder_bottom_dist | right_shoulder_top_dist | right_shoulder_bottom_dist | left_elbow_top_dist | left_elbow_bottom_dist | right_elbow_top_dist | right_elbow_bottom_dist | left_wrist_top_dist | left_wrist_bottom_dist | right_wrist_top_dist | right_wrist_bottom_dist | left_hip_top_dist | left_hip_bottom_dist | right_hip_top_dist | right_hip_bottom_dist | left_knee_top_dist | left_knee_bottom_dist | right_knee_top_dist | right_knee_bottom_dist | left_ankle_top_dist | left_ankle_bottom_dist | right_ankle_top_dist | right_ankle_bottom_dist | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 139.691 | 453.810 | 151.440 | 460.771 | 113.032 | 476.286 | 180.259 | 445.126 | 101.246 | 478.053 | 224.946 | 388.402 | 163.677 | 412.205 | 291.861 | 332.618 | 218.935 | 368.847 | 319.802 | 276.817 | 235.590 | 342.005 | 352.147 | 229.775 | 330.627 | 247.948 | 457.988 | 118.041 | 400.249 | 210.554 | 426.089 | 152.056 | 458.407 | 194.857 |
| 1 | 219.240 | 376.907 | 107.062 | 464.210 | 208.241 | 395.238 | 139.040 | 432.574 | 202.198 | 386.158 | 170.682 | 399.706 | 237.697 | 349.583 | 130.723 | 440.394 | 287.228 | 340.067 | 95.316 | 481.054 | 291.823 | 375.793 | 306.436 | 272.108 | 332.235 | 238.045 | 374.111 | 226.972 | 393.302 | 177.855 | 447.702 | 165.827 | 464.532 | 105.850 |
| 2 | 114.684 | 464.978 | 121.393 | 460.750 | 209.028 | 415.961 | 139.339 | 438.516 | 210.612 | 412.764 | 180.103 | 396.358 | 244.709 | 353.241 | 117.177 | 462.027 | 254.459 | 392.036 | 107.047 | 483.412 | 254.249 | 442.271 | 334.531 | 250.052 | 365.415 | 211.029 | 409.651 | 202.716 | 429.890 | 146.674 | 489.473 | 148.322 | 489.456 | 103.502 |
| 3 | 150.096 | 505.597 | 155.437 | 516.805 | 127.744 | 524.638 | 185.402 | 504.764 | 125.420 | 520.907 | 242.182 | 436.003 | 178.191 | 464.880 | 308.353 | 359.789 | 245.235 | 406.229 | 362.151 | 296.329 | 311.701 | 352.524 | 369.434 | 274.015 | 348.848 | 301.257 | 464.828 | 182.184 | 445.466 | 225.565 | 543.030 | 128.115 | 531.762 | 177.651 |
| 4 | 91.655 | 500.699 | 88.932 | 502.501 | 89.834 | 501.079 | 122.090 | 470.116 | 167.362 | 470.016 | 160.697 | 430.627 | 194.623 | 439.693 | 129.537 | 468.497 | 212.710 | 471.281 | 84.680 | 507.193 | 183.968 | 515.070 | 308.260 | 285.770 | 327.234 | 268.397 | 381.836 | 239.404 | 422.678 | 168.536 | 479.981 | 165.535 | 507.097 | 90.993 |
| 5 | 190.423 | 472.569 | 179.159 | 487.789 | 172.724 | 488.188 | 131.322 | 488.105 | 136.639 | 483.716 | 169.193 | 435.949 | 209.694 | 408.771 | 239.258 | 375.096 | 310.914 | 304.460 | 271.681 | 333.434 | 289.150 | 337.040 | 329.403 | 282.248 | 353.680 | 251.499 | 447.742 | 172.448 | 467.127 | 140.664 | 547.518 | 117.861 | 567.176 | 64.311 |
| 6 | 142.212 | 458.133 | 136.621 | 473.452 | 116.796 | 480.265 | 155.741 | 472.965 | 103.867 | 489.563 | 221.702 | 394.308 | 180.226 | 415.960 | 300.493 | 308.431 | 263.732 | 342.875 | 364.402 | 238.180 | 337.507 | 279.494 | 329.515 | 265.448 | 312.568 | 285.209 | 422.124 | 171.750 | 414.752 | 195.807 | 488.571 | 113.838 | 492.155 | 138.798 |
| 7 | 118.411 | 437.884 | 110.964 | 454.636 | 96.762 | 457.973 | 135.269 | 443.555 | 101.644 | 451.652 | 199.977 | 375.700 | 158.455 | 396.762 | 280.915 | 285.278 | 247.099 | 316.309 | 344.566 | 216.070 | 329.922 | 244.375 | 325.652 | 228.244 | 312.485 | 246.740 | 409.378 | 146.260 | 405.849 | 163.278 | 479.062 | 91.341 | 475.298 | 110.771 |
| 8 | 179.026 | 501.837 | 174.395 | 509.670 | 176.691 | 516.647 | 111.132 | 530.799 | 170.003 | 517.505 | 173.186 | 468.816 | 238.792 | 433.049 | 277.820 | 377.785 | 333.128 | 325.585 | 348.933 | 315.665 | 400.402 | 253.969 | 354.905 | 290.880 | 378.720 | 261.624 | 464.386 | 197.124 | 471.840 | 167.764 | 571.270 | 159.135 | 583.359 | 62.913 |
# Dropping the Pose feature as we have got the distances
hp_data.drop(labels=['Pose'], axis=1, inplace=True)
# Creating the final dataframe having:
#### Image Name
#### Respective TOP & BOTTOM distances of every body part
#### TGT --> Height
hp_engg_df = pd.concat([hp_data['Depthmap Image'], body_parts_both_dists_df,hp_data['Height(cm)']], axis=1)
hp_engg_df.rename(columns={'Height(cm)':'Height', 'Depthmap Image': 'Img_name'}, inplace=True)
# Shape of the final dataframe
hp_engg_df.shape
(9, 36)
OBSERVATION
# Checking some of the records
hp_engg_df.head()
| Img_name | nose_top_dist | nose_bottom_dist | left_eye_top_dist | left_eye_bottom_dist | right_eye_top_dist | right_eye_bottom_dist | left_ear_top_dist | left_ear_bottom_dist | right_ear_top_dist | right_ear_bottom_dist | left_shoulder_top_dist | left_shoulder_bottom_dist | right_shoulder_top_dist | right_shoulder_bottom_dist | left_elbow_top_dist | left_elbow_bottom_dist | right_elbow_top_dist | right_elbow_bottom_dist | left_wrist_top_dist | left_wrist_bottom_dist | right_wrist_top_dist | right_wrist_bottom_dist | left_hip_top_dist | left_hip_bottom_dist | right_hip_top_dist | right_hip_bottom_dist | left_knee_top_dist | left_knee_bottom_dist | right_knee_top_dist | right_knee_bottom_dist | left_ankle_top_dist | left_ankle_bottom_dist | right_ankle_top_dist | right_ankle_bottom_dist | Height | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1d5fee00-ada4-11eb-a80b-3f50af21830f | 139.691 | 453.810 | 151.440 | 460.771 | 113.032 | 476.286 | 180.259 | 445.126 | 101.246 | 478.053 | 224.946 | 388.402 | 163.677 | 412.205 | 291.861 | 332.618 | 218.935 | 368.847 | 319.802 | 276.817 | 235.590 | 342.005 | 352.147 | 229.775 | 330.627 | 247.948 | 457.988 | 118.041 | 400.249 | 210.554 | 426.089 | 152.056 | 458.407 | 194.857 | 76.7 |
| 1 | 1eddf4c0-ad9f-11eb-a80b-ef4adba049aa | 219.240 | 376.907 | 107.062 | 464.210 | 208.241 | 395.238 | 139.040 | 432.574 | 202.198 | 386.158 | 170.682 | 399.706 | 237.697 | 349.583 | 130.723 | 440.394 | 287.228 | 340.067 | 95.316 | 481.054 | 291.823 | 375.793 | 306.436 | 272.108 | 332.235 | 238.045 | 374.111 | 226.972 | 393.302 | 177.855 | 447.702 | 165.827 | 464.532 | 105.850 | 66.4 |
| 2 | 38e29bc0-8fc0-11eb-b5f2-0742da91b282 | 114.684 | 464.978 | 121.393 | 460.750 | 209.028 | 415.961 | 139.339 | 438.516 | 210.612 | 412.764 | 180.103 | 396.358 | 244.709 | 353.241 | 117.177 | 462.027 | 254.459 | 392.036 | 107.047 | 483.412 | 254.249 | 442.271 | 334.531 | 250.052 | 365.415 | 211.029 | 409.651 | 202.716 | 429.890 | 146.674 | 489.473 | 148.322 | 489.456 | 103.502 | 63.2 |
| 3 | 6cd5d480-8b8b-11eb-b152-f7b115384fa9 | 150.096 | 505.597 | 155.437 | 516.805 | 127.744 | 524.638 | 185.402 | 504.764 | 125.420 | 520.907 | 242.182 | 436.003 | 178.191 | 464.880 | 308.353 | 359.789 | 245.235 | 406.229 | 362.151 | 296.329 | 311.701 | 352.524 | 369.434 | 274.015 | 348.848 | 301.257 | 464.828 | 182.184 | 445.466 | 225.565 | 543.030 | 128.115 | 531.762 | 177.651 | 87.1 |
| 4 | 76ed6fc0-8e1d-11eb-ad70-7be1a1219834 | 91.655 | 500.699 | 88.932 | 502.501 | 89.834 | 501.079 | 122.090 | 470.116 | 167.362 | 470.016 | 160.697 | 430.627 | 194.623 | 439.693 | 129.537 | 468.497 | 212.710 | 471.281 | 84.680 | 507.193 | 183.968 | 515.070 | 308.260 | 285.770 | 327.234 | 268.397 | 381.836 | 239.404 | 422.678 | 168.536 | 479.981 | 165.535 | 507.097 | 90.993 | 59.1 |
# Saving the dataframe
hp_engg_df.to_csv("HP_data_engg.csv")
def hist_plot(df, col, bp_label, top_flag=True):
"""
Description : This function is created for plotting the histogram of a specific feature.
Input Parameters : It accepts 4 inputs:
- df : `pandas dataframe`
Dataframe containig the entire records.
- col : `str`
Feature name which you want to plot.
- bp_label : `str`
Variable that represents the respective body part.
- top_flag : `str`
Binary variable that represents whether it is the TOP or BOTTOM distance.
Returns : None
- It only plots the histogram.
"""
# Label of Body part
bp_lbl = str(bp_label).upper()
# Flag for representing the TOP or BOTTOM distance
if top_flag:
tb_str = "TOP"
else:
tb_str = "BOTTOM"
# Plotting the Histogram
with plt.style.context('seaborn'):
sns.displot(data=df, x=col, kind='hist', label=bp_lbl, height=7, aspect=1.2)
# Providing the labels and title to the graph
plt.xlabel(col, fontdict=label_font_dict)
plt.xticks(rotation=15)
plt.ylabel("Number or samples\n", fontdict=label_font_dict)
plt.minorticks_on()
plt.grid(which='major', linestyle="--", color='lightpink')
plt.title("Samples --> {} to {} distances\n".format(bp_lbl, tb_str), fontdict=title_font_dict)
plt.legend();
def kde_plot(df, col, bp_label, top_flag=True):
"""
Description : This function is created for plotting the distribution of a specific feature.
Input Parameters : It accepts 4 inputs:
- df : `pandas dataframe`
Dataframe containig the entire records.
- col : `str`
Feature name which you want to plot.
- bp_label : `str`
Variable that represents the respective body part.
- top_flag : `str`
Binary variable that represents whether it is the TOP or BOTTOM distance.
Returns : None
- It only plots the distribution.
"""
# Label of Body part
bp_lbl = str(bp_label).upper()
# Flag for representing the TOP or BOTTOM distance
if top_flag:
tb_str = "TOP"
else:
tb_str = "BOTTOM"
# Plotting the KDE
with plt.style.context('seaborn'):
sns.displot(data=df, x=col, kind='kde', label=bp_lbl, height=7, aspect=1.2)
# Providing the labels and title to the graph
plt.xlabel(col, fontdict=label_font_dict)
plt.xticks(rotation=15)
plt.minorticks_on()
plt.grid(which='major', linestyle="--", color='lightpink')
plt.title("Samples distribution of {} to {} distances\n".format(bp_lbl, tb_str), fontdict=title_font_dict)
plt.legend();
def box_plot(df, col, bp_label, top_flag=True):
"""
Description : This function is created for plotting the box-plot of a specific feature.
Input Parameters : It accepts 4 inputs:
- df : `pandas dataframe`
Dataframe containig the entire records.
- col : `str`
Feature name which you want to plot.
- bp_label : `str`
Variable that represents the respective body part.
- top_flag : `str`
Binary variable that represents whether it is the TOP or BOTTOM distance.
Returns : None
- It only plots the box-plot.
"""
# Label of Body part
bp_lbl = str(bp_label).upper()
# Flag for representing the TOP or BOTTOM distance
if top_flag:
tb_str = "TOP"
else:
tb_str = "BOTTOM"
# Plotting the Box-plot
with plt.style.context('seaborn'):
plt.figure(figsize=(10,5))
sns.boxplot(data=df, x=col, palette='prism')
# Providing the labels and title to the graph
plt.xlabel(col, fontdict=label_font_dict)
plt.xticks(rotation=15)
plt.minorticks_on()
plt.grid(which='major', linestyle="--", color='lightpink')
plt.title("How the {} to {} distances look like?\n".format(bp_lbl, tb_str), fontdict=title_font_dict)
def strip_plot(df, col, bp_label, top_flag=True):
"""
Description : This function is created for plotting the stripplot of a specific feature.
Input Parameters : It accepts 4 inputs:
- df : `pandas dataframe`
Dataframe containig the entire records.
- col : `str`
Feature name which you want to plot.
- bp_label : `str`
Variable that represents the respective body part.
- top_flag : `str`
Binary variable that represents whether it is the TOP or BOTTOM distance.
Returns : None
- It only plots the Stripplot and tells how far the data points from the central value.
"""
# Label of Body part
bp_lbl = str(bp_label).upper()
# Flag for representing the TOP or BOTTOM distance
if top_flag:
tb_str = "TOP"
else:
tb_str = "BOTTOM"
# Plotting the Data points
with plt.style.context('seaborn-poster'):
plt.figure(figsize=(10,6))
sns.stripplot(data=df, x=col, palette='plasma', size=8, label=bp_lbl)
plt.axvline(df[col].mean(), linestyle="--", label='Mean')
plt.axvline(df[col].median(), linestyle=":", label='Median')
# Providing the labels and title to the graph
plt.xlabel(col, fontdict=label_font_dict)
plt.xticks(rotation=15)
plt.minorticks_on()
plt.grid(which='major', linestyle="--", color='lightpink')
plt.title("Where the {} to {} distances stand?\n".format(bp_lbl, tb_str), fontdict=title_font_dict)
plt.legend()
NOSE_top_dist¶hist_plot(df=hp_engg_df, col='nose_top_dist', bp_label="nose", top_flag=True)
OBSERVATION
kde_plot(df=hp_engg_df, col='nose_top_dist', bp_label="nose", top_flag=True)
OBSERVATION
box_plot(df=hp_engg_df, col='nose_top_dist', bp_label="nose", top_flag=True)
OBSERVATION
strip_plot(df=hp_engg_df, col='nose_top_dist', bp_label="nose", top_flag=True)
OBSERVATION
NOSE_bottom_dist¶hist_plot(df=hp_engg_df, col='nose_bottom_dist', bp_label="nose", top_flag=False)
OBSERVATION
kde_plot(df=hp_engg_df, col='nose_bottom_dist', bp_label="nose", top_flag=False)
OBSERVATION
box_plot(df=hp_engg_df, col='nose_bottom_dist', bp_label="nose", top_flag=False)
OBSERVATION
strip_plot(df=hp_engg_df, col='nose_bottom_dist', bp_label="nose", top_flag=False)
OBSERVATION
LEFT_EYE_top_dist¶hist_plot(df=hp_engg_df, col='left_eye_top_dist', bp_label="left_eye", top_flag=True)
OBSERVATION
kde_plot(df=hp_engg_df, col='left_eye_top_dist', bp_label="left_eye", top_flag=True)
OBSERVATION
box_plot(df=hp_engg_df, col='left_eye_top_dist', bp_label="left_eye", top_flag=True)
OBSERVATION
strip_plot(df=hp_engg_df, col='left_eye_top_dist', bp_label="left_eye", top_flag=True)
OBSERVATION
RIGHT_SHOULDER_top_dist¶hist_plot(df=hp_engg_df, col='right_shoulder_top_dist', bp_label="right_shoulder", top_flag=True)
OBSERVATION
kde_plot(df=hp_engg_df, col='right_shoulder_top_dist', bp_label="right_shoulder", top_flag=True)
OBSERVATION
box_plot(df=hp_engg_df, col='right_shoulder_top_dist', bp_label="right_shoulder", top_flag=True)
OBSERVATION
strip_plot(df=hp_engg_df, col='right_shoulder_top_dist', bp_label="right_shoulder", top_flag=True)
OBSERVATION
RIGHT_ELBOW_top_dist¶hist_plot(df=hp_engg_df, col='right_elbow_top_dist', bp_label="right_elbow", top_flag=True)
OBSERVATION
kde_plot(df=hp_engg_df, col='right_elbow_top_dist', bp_label="right_elbow", top_flag=True)
OBSERVATION
box_plot(df=hp_engg_df, col='right_elbow_top_dist', bp_label="right_elbow", top_flag=True)
OBSERVATION
strip_plot(df=hp_engg_df, col='right_elbow_top_dist', bp_label="right_elbow", top_flag=True)
OBSERVATION
LEFT_WRIST_top_dist¶hist_plot(df=hp_engg_df, col='left_wrist_top_dist', bp_label="left_wrist", top_flag=True)
OBSERVATION
kde_plot(df=hp_engg_df, col='left_wrist_top_dist', bp_label="left_wrist", top_flag=True)
OBSERVATION
box_plot(df=hp_engg_df, col='left_wrist_top_dist', bp_label="left_wrist", top_flag=True)
OBSERVATION
strip_plot(df=hp_engg_df, col='left_wrist_top_dist', bp_label="left_wrist", top_flag=True)
OBSERVATION
RIGHT_HIP_top_dist¶hist_plot(df=hp_engg_df, col='right_hip_top_dist', bp_label="right_hip", top_flag=True)
OBSERVATION
kde_plot(df=hp_engg_df, col='right_hip_top_dist', bp_label="right_hip", top_flag=True)
OBSERVATION
box_plot(df=hp_engg_df, col='right_hip_top_dist', bp_label="right_hip", top_flag=True)
OBSERVATION
strip_plot(df=hp_engg_df, col='right_hip_top_dist', bp_label="right_hip", top_flag=True)
OBSERVATION
LEFT_KNEE_bottom_dist¶hist_plot(df=hp_engg_df, col='left_knee_bottom_dist', bp_label="left_knee", top_flag=True)
OBSERVATION
kde_plot(df=hp_engg_df, col='left_knee_bottom_dist', bp_label="left_knee", top_flag=True)
OBSERVATION
box_plot(df=hp_engg_df, col='left_knee_bottom_dist', bp_label="left_knee", top_flag=True)
OBSERVATION
strip_plot(df=hp_engg_df, col='left_knee_bottom_dist', bp_label="left_knee", top_flag=True)
OBSERVATION
RIGHT_ANKLE_bottom_dist¶hist_plot(df=hp_engg_df, col='right_ankle_bottom_dist', bp_label="right_ankle", top_flag=True)
OBSERVATION
kde_plot(df=hp_engg_df, col='right_ankle_bottom_dist', bp_label="right_ankle", top_flag=True)
OBSERVATION
box_plot(df=hp_engg_df, col='right_ankle_bottom_dist', bp_label="right_ankle", top_flag=True)
OBSERVATION
strip_plot(df=hp_engg_df, col='right_ankle_bottom_dist', bp_label="right_ankle", top_flag=True)
OBSERVATION
hp_engg_df['Img_name'] = hp_engg_df['Img_name'].apply(lambda val: os.path.join(os.path.join(os.getcwd(), "Dataset"), val+".jpg"))
hp_engg_df
| Img_name | nose_top_dist | nose_bottom_dist | left_eye_top_dist | left_eye_bottom_dist | right_eye_top_dist | right_eye_bottom_dist | left_ear_top_dist | left_ear_bottom_dist | right_ear_top_dist | right_ear_bottom_dist | left_shoulder_top_dist | left_shoulder_bottom_dist | right_shoulder_top_dist | right_shoulder_bottom_dist | left_elbow_top_dist | left_elbow_bottom_dist | right_elbow_top_dist | right_elbow_bottom_dist | left_wrist_top_dist | left_wrist_bottom_dist | right_wrist_top_dist | right_wrist_bottom_dist | left_hip_top_dist | left_hip_bottom_dist | right_hip_top_dist | right_hip_bottom_dist | left_knee_top_dist | left_knee_bottom_dist | right_knee_top_dist | right_knee_bottom_dist | left_ankle_top_dist | left_ankle_bottom_dist | right_ankle_top_dist | right_ankle_bottom_dist | Height | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | E:\STUDY\PROJECTS\Assignment_CGM\Dataset\1d5fe... | 139.691 | 453.810 | 151.440 | 460.771 | 113.032 | 476.286 | 180.259 | 445.126 | 101.246 | 478.053 | 224.946 | 388.402 | 163.677 | 412.205 | 291.861 | 332.618 | 218.935 | 368.847 | 319.802 | 276.817 | 235.590 | 342.005 | 352.147 | 229.775 | 330.627 | 247.948 | 457.988 | 118.041 | 400.249 | 210.554 | 426.089 | 152.056 | 458.407 | 194.857 | 76.7 |
| 1 | E:\STUDY\PROJECTS\Assignment_CGM\Dataset\1eddf... | 219.240 | 376.907 | 107.062 | 464.210 | 208.241 | 395.238 | 139.040 | 432.574 | 202.198 | 386.158 | 170.682 | 399.706 | 237.697 | 349.583 | 130.723 | 440.394 | 287.228 | 340.067 | 95.316 | 481.054 | 291.823 | 375.793 | 306.436 | 272.108 | 332.235 | 238.045 | 374.111 | 226.972 | 393.302 | 177.855 | 447.702 | 165.827 | 464.532 | 105.850 | 66.4 |
| 2 | E:\STUDY\PROJECTS\Assignment_CGM\Dataset\38e29... | 114.684 | 464.978 | 121.393 | 460.750 | 209.028 | 415.961 | 139.339 | 438.516 | 210.612 | 412.764 | 180.103 | 396.358 | 244.709 | 353.241 | 117.177 | 462.027 | 254.459 | 392.036 | 107.047 | 483.412 | 254.249 | 442.271 | 334.531 | 250.052 | 365.415 | 211.029 | 409.651 | 202.716 | 429.890 | 146.674 | 489.473 | 148.322 | 489.456 | 103.502 | 63.2 |
| 3 | E:\STUDY\PROJECTS\Assignment_CGM\Dataset\6cd5d... | 150.096 | 505.597 | 155.437 | 516.805 | 127.744 | 524.638 | 185.402 | 504.764 | 125.420 | 520.907 | 242.182 | 436.003 | 178.191 | 464.880 | 308.353 | 359.789 | 245.235 | 406.229 | 362.151 | 296.329 | 311.701 | 352.524 | 369.434 | 274.015 | 348.848 | 301.257 | 464.828 | 182.184 | 445.466 | 225.565 | 543.030 | 128.115 | 531.762 | 177.651 | 87.1 |
| 4 | E:\STUDY\PROJECTS\Assignment_CGM\Dataset\76ed6... | 91.655 | 500.699 | 88.932 | 502.501 | 89.834 | 501.079 | 122.090 | 470.116 | 167.362 | 470.016 | 160.697 | 430.627 | 194.623 | 439.693 | 129.537 | 468.497 | 212.710 | 471.281 | 84.680 | 507.193 | 183.968 | 515.070 | 308.260 | 285.770 | 327.234 | 268.397 | 381.836 | 239.404 | 422.678 | 168.536 | 479.981 | 165.535 | 507.097 | 90.993 | 59.1 |
| 5 | E:\STUDY\PROJECTS\Assignment_CGM\Dataset\8d23f... | 190.423 | 472.569 | 179.159 | 487.789 | 172.724 | 488.188 | 131.322 | 488.105 | 136.639 | 483.716 | 169.193 | 435.949 | 209.694 | 408.771 | 239.258 | 375.096 | 310.914 | 304.460 | 271.681 | 333.434 | 289.150 | 337.040 | 329.403 | 282.248 | 353.680 | 251.499 | 447.742 | 172.448 | 467.127 | 140.664 | 547.518 | 117.861 | 567.176 | 64.311 | 86.4 |
| 6 | E:\STUDY\PROJECTS\Assignment_CGM\Dataset\9dc3e... | 142.212 | 458.133 | 136.621 | 473.452 | 116.796 | 480.265 | 155.741 | 472.965 | 103.867 | 489.563 | 221.702 | 394.308 | 180.226 | 415.960 | 300.493 | 308.431 | 263.732 | 342.875 | 364.402 | 238.180 | 337.507 | 279.494 | 329.515 | 265.448 | 312.568 | 285.209 | 422.124 | 171.750 | 414.752 | 195.807 | 488.571 | 113.838 | 492.155 | 138.798 | 100.6 |
| 7 | E:\STUDY\PROJECTS\Assignment_CGM\Dataset\9dd02... | 118.411 | 437.884 | 110.964 | 454.636 | 96.762 | 457.973 | 135.269 | 443.555 | 101.644 | 451.652 | 199.977 | 375.700 | 158.455 | 396.762 | 280.915 | 285.278 | 247.099 | 316.309 | 344.566 | 216.070 | 329.922 | 244.375 | 325.652 | 228.244 | 312.485 | 246.740 | 409.378 | 146.260 | 405.849 | 163.278 | 479.062 | 91.341 | 475.298 | 110.771 | 106.1 |
| 8 | E:\STUDY\PROJECTS\Assignment_CGM\Dataset\d3757... | 179.026 | 501.837 | 174.395 | 509.670 | 176.691 | 516.647 | 111.132 | 530.799 | 170.003 | 517.505 | 173.186 | 468.816 | 238.792 | 433.049 | 277.820 | 377.785 | 333.128 | 325.585 | 348.933 | 315.665 | 400.402 | 253.969 | 354.905 | 290.880 | 378.720 | 261.624 | 464.386 | 197.124 | 471.840 | 167.764 | 571.270 | 159.135 | 583.359 | 62.913 | 99.9 |
Chidlren - I¶with plt.style.context('seaborn'):
plt.figure(figsize=(10,8))
img = cv2.imread(hp_engg_df['Img_name'].iloc[0])
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# Displaying the image and setting its title
plt.imshow(img, aspect='auto')
plt.axis('off')
plt.title("Image name is --> {}".format(hp_engg_df['Img_name'].iloc[0].split("\\")[-1]), fontdict=label_font_dict)
OBSERVATION
Chidlren - II¶with plt.style.context('seaborn'):
plt.figure(figsize=(10,8))
img = cv2.imread(hp_engg_df['Img_name'].iloc[3])
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# Displaying the image and setting its title
plt.imshow(img, aspect='auto')
plt.axis('off')
plt.title("Image name is --> {}".format(hp_engg_df['Img_name'].iloc[3].split("\\")[-1]), fontdict=label_font_dict)
OBSERVATION
Chidlren - III¶with plt.style.context('seaborn'):
plt.figure(figsize=(10,8))
img = cv2.imread(hp_engg_df['Img_name'].iloc[6])
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# Displaying the image and setting its title
plt.imshow(img, aspect='auto')
plt.axis('off')
plt.title("Image name is --> {}".format(hp_engg_df['Img_name'].iloc[6].split("\\")[-1]), fontdict=label_font_dict)
OBSERVATION
Chidlren - IV¶with plt.style.context('seaborn'):
plt.figure(figsize=(10,8))
img = cv2.imread(hp_engg_df['Img_name'].iloc[8])
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# Displaying the image and setting its title
plt.imshow(img, aspect='auto')
plt.axis('off')
plt.title("Image name is --> {}".format(hp_engg_df['Img_name'].iloc[8].split("\\")[-1]), fontdict=label_font_dict)
OBSERVATION

OBSERVATION
all_images_loc = os.path.join(os.getcwd(), "Dataset")
all_images_loc
'E:\\STUDY\\PROJECTS\\Assignment_CGM\\Dataset'
hp_engg_df['Img_name'].iloc[4]
'E:\\STUDY\\PROJECTS\\Assignment_CGM\\Dataset\\76ed6fc0-8e1d-11eb-ad70-7be1a1219834.jpg'
Image Filtering¶# Read the image
img = cv2.imread(hp_engg_df['Img_name'].iloc[6])
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# Defining the kernel
kernel = np.ones((9,9),np.float32)/81
img_filtering = cv2.filter2D(img, ddepth=-1, kernel=kernel)
# Print Just few cells
print(img_filtering[0], "\n")
# Visualize the original & filtered image
with plt.style.context('seaborn'):
fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(15,8), sharex=True, sharey=True)
# Original image
ax[0].imshow(img, aspect='auto')
ax[0].set_title("Original", fontdict= label_font_dict)
ax[0].axis("off")
# Filtered image
ax[1].imshow(img_filtering, aspect='auto')
ax[1].set_title("Smoothing using Filtering", fontdict= label_font_dict)
ax[1].axis("off")
plt.tight_layout()
[[ 1 1 1] [ 1 1 1] [ 1 1 1] ... [51 51 51] [63 63 63] [76 76 76]]
OBSERVATION
Image Blurring¶Averaging¶# Image blurring -- averaging
img_avg_blur = cv2.blur(img, ksize=(9,9))
# Print Just few cells
print(img_avg_blur[0], "\n")
# Does image filtering and avg blurring yields the same resultant array?
print("Does image filtering and avg blurring yields the same resultant array? --> {}\n".format(np.all(np.ravel(img_filtering) == np.ravel(img_avg_blur)), "\n"))
# Visualize the original & blurred image
with plt.style.context('seaborn'):
fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(15,8), sharex=True, sharey=True)
# Original image
ax[0].imshow(img, aspect='auto')
ax[0].set_title("Original", fontdict= label_font_dict)
ax[0].axis("off")
# Averaging Blur image
ax[1].imshow(img_avg_blur, aspect='auto')
ax[1].set_title("Image Blurring -- Averaging", fontdict= label_font_dict)
ax[1].axis("off")
plt.tight_layout()
[[ 1 1 1] [ 1 1 1] [ 1 1 1] ... [51 51 51] [63 63 63] [76 76 76]] Does image filtering and avg blurring yields the same resultant array? --> True
Gaussian Blurring¶# Image blurring -- gaussian
img_gauss_blur = cv2.blur(img, ksize=(9,9))
# Print Just few cells
print(img_gauss_blur[0], "\n")
# Does image avg blurring and gauss blurring yields the same resultant array?
print("Does image avg blurring and gauss blurring yields the same resultant array? --> {}\n".format(np.all(np.ravel(img_avg_blur) == np.ravel(img_gauss_blur)), "\n"))
# Visualize the original & gauss blurred image
with plt.style.context('seaborn'):
fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(15,8), sharex=True, sharey=True)
# Original image
ax[0].imshow(img, aspect='auto')
ax[0].set_title("Original", fontdict= label_font_dict)
ax[0].axis("off")
# Gaussian blur image
ax[1].imshow(img_gauss_blur, aspect='auto')
ax[1].set_title("Image Blurring -- Gaussian", fontdict= label_font_dict)
ax[1].axis("off")
plt.tight_layout()
[[ 1 1 1] [ 1 1 1] [ 1 1 1] ... [51 51 51] [63 63 63] [76 76 76]] Does image avg blurring and gauss blurring yields the same resultant array? --> True
Median Blurring¶# Image blurring -- median
img_median_blur = cv2.medianBlur(img, ksize=9)
# Print Just few cells
print(img_median_blur[0], "\n")
# Does image avg blurring and median blurring yields the same resultant array?
print("Does image avg blurring and median blurring yields the same resultant array? --> {}\n".format(np.all(np.ravel(img_avg_blur) == np.ravel(img_median_blur)), "\n"))
# Visualize the original & median blurred image
with plt.style.context('seaborn'):
fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(15,8), sharex=True, sharey=True)
# Original image
ax[0].imshow(img, aspect='auto')
ax[0].set_title("Original", fontdict= label_font_dict)
ax[0].axis("off")
# Median blur image
ax[1].imshow(img_median_blur, aspect='auto')
ax[1].set_title("Image Blurring -- Median", fontdict= label_font_dict)
ax[1].axis("off")
plt.tight_layout()
[[0 0 0] [0 0 0] [0 0 0] ... [0 0 0] [1 1 1] [1 1 1]] Does image avg blurring and median blurring yields the same resultant array? --> False
Bi-lateral Filtering¶# Image blurring -- bi-lateral
img_bilateral_blur = cv2.bilateralFilter(img, d=41, sigmaColor=25, sigmaSpace=175)
# Print Just few cells
print(img_bilateral_blur[0], "\n")
# Does image avg blurring and median blurring yields the same resultant array?
print("Does image gaussian blurring and bi-lateral filtering yields the same resultant array? --> {}\n".format(np.all(np.ravel(img_gauss_blur) == np.ravel(img_bilateral_blur)), "\n"))
# Visualize the original & median blurred image
with plt.style.context('seaborn'):
fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(15,8), sharex=True, sharey=True)
# Original image
ax[0].imshow(img, aspect='auto')
ax[0].set_title("Original", fontdict= label_font_dict)
ax[0].axis("off")
# Bi-lateral filtering image
ax[1].imshow(img_bilateral_blur, aspect='auto')
ax[1].set_title("Image Blurring -- Bi-lateral", fontdict= label_font_dict)
ax[1].axis("off")
plt.tight_layout()
[[0 0 0] [0 0 0] [0 0 0] ... [0 0 0] [0 0 0] [0 0 0]] Does image gaussian blurring and bi-lateral filtering yields the same resultant array? --> False
OBSERVATION
Image De-noising¶# Image de-noising
img_dn = cv2.fastNlMeansDenoisingColored(img, dst=None, h=21, hColor=21, templateWindowSize=21, searchWindowSize=31)
# Print Just few cells
print(img_dn[0], "\n")
# Does image bi-lateral filtering and image de-noising yields the same resultant array?
print("Does image bi-lateral filtering and de-noising yields the same resultant array? --> {}\n".format(np.all(np.ravel(img_bilateral_blur) == np.ravel(img_dn)), "\n"))
# Visualize the original & de-noised image
with plt.style.context('seaborn'):
fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(15,8), sharex=True, sharey=True)
# Original image
ax[0].imshow(img, aspect='auto')
ax[0].set_title("Original", fontdict= label_font_dict)
ax[0].axis("off")
# De-noised image
ax[1].imshow(img_dn, aspect='auto')
ax[1].set_title("Image De-noising", fontdict= label_font_dict)
ax[1].axis("off")
plt.tight_layout()
[[0 0 0] [1 1 1] [0 0 0] ... [0 0 0] [0 0 0] [1 1 1]] Does image bi-lateral filtering and de-noising yields the same resultant array? --> False
OBSERVATION
# Grayscale image
img_gray = cv2.imread(hp_engg_df['Img_name'].iloc[6])
# All techniques at one place
with plt.style.context('seaborn'):
fig, ax = plt.subplots(nrows=4, ncols=2, figsize=(16,25), sharex=True, sharey=True)
# Original image
ax[0,0].imshow(img, aspect='auto')
ax[0,0].set_title("Original", fontdict= label_font_dict)
ax[0,0].axis("off")
# Grayscale image
ax[0,1].imshow(img_gray, aspect='auto')
ax[0,1].set_title("Image Grayscale", fontdict= label_font_dict)
ax[0,1].axis("off")
# Image after filtering image
ax[1,0].imshow(img_filtering, aspect='auto')
ax[1,0].set_title("Image Filtering", fontdict= label_font_dict)
ax[1,0].axis("off")
# Image after average blurring
ax[1,1].imshow(img_avg_blur, aspect='auto')
ax[1,1].set_title("Image Averaging", fontdict= label_font_dict)
ax[1,1].axis("off")
# Image after gaussian blurring
ax[2,0].imshow(img_gauss_blur, aspect='auto')
ax[2,0].set_title("Gauss Blur", fontdict= label_font_dict)
ax[2,0].axis("off")
# Image after median blurring
ax[2,1].imshow(img_median_blur, aspect='auto')
ax[2,1].set_title("Median Blur", fontdict= label_font_dict)
ax[2,1].axis("off")
# Image after bi-lateral filtering
ax[3,0].imshow(img_bilateral_blur, aspect='auto')
ax[3,0].set_title("Bi-lateral Blur", fontdict= label_font_dict)
ax[3,0].axis("off")
# Image after de-noising
ax[3,1].imshow(img_dn, aspect='auto')
ax[3,1].set_title("De-noised image", fontdict= label_font_dict)
ax[3,1].axis("off")
plt.tight_layout()
OBSERVATION
Bi-lateral blur and De-noising are behaving in the similar manner apart from the slight smoothing of the non-black boundary pixels of the object in the latter.
Median blurring the image looks more stable as here we got rid-off the noise and imp features are still visible.
Edge detection is one of the fundamental operation in image processing. Using this, we can reduce the amount of pixels while maintaining the structural aspects of the images.Types of filters¶Sobel : This filter simply adds a little bit more weight or value to the middle.Scharr : Besides adding even more weight to the middle, this filter also adds weight to the sidesLaplacian : Second derivative based Laplacian filter(for finer edges)def sobel_edge_detection(image):
"""
Description : This function is performing the SOBEL edge detection horizontally and vertically.
Input parameters : It accepts below inputs:
- Original Image
- Depth of the destination image
- Order of derivative x --> horizontally
- Order of derivative y --> vertically
- Kernel size for convolutions
Returns : It returns 2 objects:
- sobel_x : Edge detected on x axis
- sobel_y : Edge detected on y axis
"""
# Horizontal edge detection
sobel_x = cv2.Sobel(image, cv2.CV_64F, 1, 0, ksize = 7)
# Vertical edge detection
sobel_y = cv2.Sobel(image, cv2.CV_64F, 0, 1, ksize = 7)
# Laplacian edge detection
laplacian = cv2.Laplacian(image, cv2.CV_64F, ksize = 7)
# Laplacian edge detection
scharr_x = cv2.Scharr(image, cv2.CV_64F, 1, 0)
# Laplacian edge detection
scharr_y = cv2.Scharr(image, cv2.CV_64F, 0, 1)
return sobel_x, sobel_y, laplacian, scharr_x, scharr_y
# Reading the image
img2 = cv2.imread(hp_engg_df['Img_name'].iloc[2])
img2 = cv2.cvtColor(img2, cv2.COLOR_BGR2RGB)
# Image blurring -- median
img_dn2 = cv2.medianBlur(img2, ksize=9)
# SOBEL edge detection
sobel_img_x, sobel_img_y, laplacian, schrr_x, schrr_y = sobel_edge_detection(img_dn2)
# Grayscale image
img_gray2 = cv2.imread(hp_engg_df['Img_name'].iloc[2])
# All techniques at one place
with plt.style.context('seaborn'):
fig, ax = plt.subplots(nrows=4, ncols=2, figsize=(16,20), sharex=True, sharey=True)
# Original image
ax[0,0].imshow(img2, aspect='auto')
ax[0,0].set_title("Original", fontdict= label_font_dict)
ax[0,0].axis("off")
# Grayscale image
ax[0,1].imshow(img_gray2, aspect='auto')
ax[0,1].set_title("Image Grayscale", fontdict= label_font_dict)
ax[0,1].axis("off")
# Median Blur image
ax[1,0].imshow(img_dn2, aspect='auto')
ax[1,0].set_title("Median Blurred Image", fontdict= label_font_dict)
ax[1,0].axis("off")
# Laplacian edge detection
ax[1,1].imshow(laplacian, aspect='auto')
ax[1,1].set_title("Laplacian", fontdict= label_font_dict)
ax[1,1].axis("off")
# SOBEL Horizontal edge detection
ax[2,0].imshow(sobel_img_x, aspect='auto')
ax[2,0].set_title("Sobel X", fontdict= label_font_dict)
ax[2,0].axis("off")
# SOBEL Vertical edge detection
ax[2,1].imshow(sobel_img_y, aspect='auto')
ax[2,1].set_title("Sobel Y", fontdict= label_font_dict)
ax[2,1].axis("off")
# SCHARR Horizontal edge detection
ax[3,0].imshow(schrr_x, aspect='auto')
ax[3,0].set_title("Scharr X", fontdict= label_font_dict)
ax[3,0].axis("off")
# SCHARR Vertical edge detection
ax[3,1].imshow(schrr_y, aspect='auto')
ax[3,1].set_title("Scharr Y", fontdict= label_font_dict)
ax[3,1].axis("off")
plt.tight_layout()
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers). Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers). Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers). Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers). Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
OBSERVATION
def canny_edge_detection(image, th1=70, th2=100, L2_grad_flag=True):
"""
Description : This function is performing the Canny edge detection in an image.
Input parameters : It accepts below inputs:
- Original Image
- Threshold 1
- Threshold 2
- L2_grad_flag
Returns : It returns the single o/p array:
- Finds edges in an image using the Canny algorithm with custom image gradient.
"""
# Canny edge detection
canny_edg_det_img = cv2.Canny(image, th1, th2, L2_grad_flag)
return canny_edg_det_img
# Index of image that will be used
img_idx = 7
# Reading the image
img3 = cv2.imread(hp_engg_df['Img_name'].iloc[img_idx])
img3 = cv2.cvtColor(img3, cv2.COLOR_BGR2RGB)
# Image blurring -- median
img_dn3 = cv2.medianBlur(img3, ksize=9)
# Canny edge detection
min_val = 25
max_val = 60
canny_edges = canny_edge_detection(img_dn3, min_val, max_val, True)
# Grayscale image
img_gray3 = cv2.imread(hp_engg_df['Img_name'].iloc[img_idx])
# All techniques at one place
with plt.style.context('seaborn'):
fig, ax = plt.subplots(nrows=2, ncols=2, figsize=(15,13), sharex=True, sharey=True)
# Original image
ax[0,0].imshow(img3, aspect='auto')
ax[0,0].set_title("Original", fontdict= label_font_dict)
ax[0,0].axis("off")
# Grayscale image
ax[0,1].imshow(img_gray3, aspect='auto')
ax[0,1].set_title("Image Grayscale", fontdict= label_font_dict)
ax[0,1].axis("off")
# Median Blur image
ax[1,0].imshow(img_dn3, aspect='auto')
ax[1,0].set_title("Median Blurred Image", fontdict= label_font_dict)
ax[1,0].axis("off")
# Canny edge detection
ax[1,1].imshow(canny_edges, aspect='auto', cmap="gray")
ax[1,1].set_title("Canny Edge Detection", fontdict= label_font_dict)
ax[1,1].axis("off")
plt.tight_layout()
OBSERVATION
# Index of image that will be used
img_idx = 1
# Reading the image
img4 = cv2.imread(hp_engg_df['Img_name'].iloc[img_idx])
img4 = cv2.cvtColor(img4, cv2.COLOR_BGR2RGB)
# Image blurring -- median
img_dn4 = cv2.medianBlur(img4, ksize=9)
# Canny edge detection
min_val = 5
max_val = 18
canny_edges4 = canny_edge_detection(img_dn4, min_val, max_val, True)
# Grayscale image
img_gray4 = cv2.imread(hp_engg_df['Img_name'].iloc[img_idx])
# All techniques at one place
with plt.style.context('seaborn'):
fig, ax = plt.subplots(nrows=2, ncols=2, figsize=(15,13), sharex=True, sharey=True)
# Original image
ax[0,0].imshow(img4, aspect='auto')
ax[0,0].set_title("Original", fontdict= label_font_dict)
ax[0,0].axis("off")
# Grayscale image
ax[0,1].imshow(img_gray4, aspect='auto')
ax[0,1].set_title("Image Grayscale", fontdict= label_font_dict)
ax[0,1].axis("off")
# Median Blur image
ax[1,0].imshow(img_dn4, aspect='auto')
ax[1,0].set_title("Median Blurred Image", fontdict= label_font_dict)
ax[1,0].axis("off")
# Canny edge detection
ax[1,1].imshow(canny_edges4, aspect='auto', cmap="gray")
ax[1,1].set_title("Canny Edge Detection", fontdict= label_font_dict)
ax[1,1].axis("off")
plt.tight_layout()
OBSERVATION
SUMMARY¶By using the boundingbox coordinates we come up with the 34 new features that are the distances of a specific body part coordinates from the TOP and BOTTOM of the overall bbox coordinates.
In the EDA, we found that in some of the images the boundary pixels of the focussed object has dark or black pixels. There can be possible reasons of the same.(shown above in the EDA - II section)
We also found that the basic edge detection techniques were unable to capture the edges of the focussed object.
Whereas, the Canny Edge Detector on the Median Blurred images provided us the well captured edges of the focussed object.